#include <stdio.h>


#include "CRC8.h"
#include "CRC8_SAE_J1850.h"
#include "CRC8_SAE_J1850_ZERO.h"
#include "CRC8_8H2F.h"
#include "CRC8_CDMA2000.h"
#include "CRC8_DARC.h"
#include "CRC8_DVB_S2.h"
#include "CRC8_EBU.h"
#include "CRC8_ICODE.h"
#include "CRC8_ITU.h"
#include "CRC8_MAXIM.h"
#include "CRC8_ROHC.h"
#include "CRC8_WCDMA.h"
#include "CRC16_CCIT_ZERO.h"
#include "CRC16_ARC.h"
#include "CRC16_AUG_CCITT.h"
#include "CRC16_BUYPASS.h"
#include "CRC16_CCITT_FALSE.h"
#include "CRC16_CDMA2000.h"
#include "CRC16_DDS_110.h"
#include "CRC16_DECT_R.h"
#include "CRC16_DECT_X.h"
#include "CRC16_DNP.h"
#include "CRC16_EN_13757.h"
#include "CRC16_GENIBUS.h"
#include "CRC16_MAXIM.h"
#include "CRC16_MCRF4XX.h"
#include "CRC16_T10_DIF.h"
#include "CRC16_TELEDISK.h"
#include "CRC16_USB.h"
#include "CRC16_KERMIT.h"
#include "CRC16_MODBUS.h"
#include "CRC16_X_25.h"
#include "CRC16_XMODEM.h"
#include "CRC32.h"
#include "CRC32_BZIP2.h"
#include "CRC32_C.h"
#include "CRC32_D.h"
#include "CRC32_MPEG2.h"
#include "CRC32_POSIX.h"
#include "CRC32_Q.h"
#include "CRC32_JAMCRC.h"
#include "CRC32_XFER.h"


void crc_assert(int val, const char* s)
{
    if(!val)
    {
        printf("%s failed!\n", s);
    }
}
/**
Name                 Polynomial Initial    FinalXor   InputReflected ResultReflected
CRC8                 0x07       0x00       0x00       false          false
CRC8_SAE_J1850       0x1D       0xFF       0xFF       false          false
CRC8_SAE_J1850_ZERO  0x1D       0x00       0x00       false          false
CRC8_8H2F            0x2F       0xFF       0xFF       false          false
CRC8_CDMA2000        0x9B       0xFF       0x00       false          false
CRC8_DARC            0x39       0x00       0x00       true           true
CRC8_DVB_S2          0xD5       0x00       0x00       false          false
CRC8_EBU             0x1D       0xFF       0x00       true           true
CRC8_ICODE           0x1D       0xFD       0x00       false          false
CRC8_ITU             0x07       0x00       0x55       false          false
CRC8_MAXIM           0x31       0x00       0x00       true           true
CRC8_ROHC            0x07       0xFF       0x00       true           true
CRC8_WCDMA           0x9B       0x00       0x00       true           true
CRC16_CCIT_ZERO      0x1021     0x0000     0x0000     false          false
CRC16_ARC            0x8005     0x0000     0x0000     true           true
CRC16_AUG_CCITT      0x1021     0x1D0F     0x0000     false          false
CRC16_BUYPASS        0x8005     0x0000     0x0000     false          false
CRC16_CCITT_FALSE    0x1021     0xFFFF     0x0000     false          false
CRC16_CDMA2000       0xC867     0xFFFF     0x0000     false          false
CRC16_DDS_110        0x8005     0x800D     0x0000     false          false
CRC16_DECT_R         0x0589     0x0000     0x0001     false          false
CRC16_DECT_X         0x0589     0x0000     0x0000     false          false
CRC16_DNP            0x3D65     0x0000     0xFFFF     true           true
CRC16_EN_13757       0x3D65     0x0000     0xFFFF     false          false
CRC16_GENIBUS        0x1021     0xFFFF     0xFFFF     false          false
CRC16_MAXIM          0x8005     0x0000     0xFFFF     true           true
CRC16_MCRF4XX        0x1021     0xFFFF     0x0000     true           true
CRC16_RIELLO         0x1021     0xB2AA     0x0000     true           true
CRC16_T10_DIF        0x8BB7     0x0000     0x0000     false          false
CRC16_TELEDISK       0xA097     0x0000     0x0000     false          false
CRC16_TMS37157       0x1021     0x89EC     0x0000     true           true
CRC16_USB            0x8005     0xFFFF     0xFFFF     true           true
CRC16_A              0x1021     0xC6C6     0x0000     true           true
CRC16_KERMIT         0x1021     0x0000     0x0000     true           true
CRC16_MODBUS         0x8005     0xFFFF     0x0000     true           true
CRC16_X_25           0x1021     0xFFFF     0xFFFF     true           true
CRC16_XMODEM         0x1021     0x0000     0x0000     false          false
CRC32                0x04C11DB7 0xFFFFFFFF 0xFFFFFFFF true           true
CRC32_BZIP2          0x04C11DB7 0xFFFFFFFF 0xFFFFFFFF false          false
CRC32_C              0x1EDC6F41 0xFFFFFFFF 0xFFFFFFFF true           true
CRC32_D              0xA833982B 0xFFFFFFFF 0xFFFFFFFF true           true
CRC32_MPEG2          0x04C11DB7 0xFFFFFFFF 0x00000000 false          false
CRC32_POSIX          0x04C11DB7 0x00000000 0xFFFFFFFF false          false
CRC32_Q              0x814141AB 0x00000000 0x00000000 false          false
CRC32_JAMCRC         0x04C11DB7 0xFFFFFFFF 0x00000000 true           true
CRC32_XFER           0x000000AF 0x00000000 0x00000000 false          false
*/
int main(void)
{
// TEST:Caculate the string "123456", result list below with different crc models:
    crc_assert(0xfd ==  crc8                 (0x00, "123456", 6), "crc8"                  );
    crc_assert(0x28 ==  crc8_sae_j1850       (0xFF, "123456", 6), "crc8_sae_j1850"        );
    crc_assert(0xde ==  crc8_sae_j1850_zero  (0x00, "123456", 6), "crc8_sae_j1850_zero"   );
    crc_assert(0x91 ==  crc8_8h2f            (0xFF, "123456", 6), "crc8_8h2f"             );
    crc_assert(0xef ==  crc8_cdma2000        (0xFF, "123456", 6), "crc8_cdma2000"         );
    crc_assert(0x11 ==  crc8_darc            (0x00, "123456", 6), "crc8_darc"             );
    crc_assert(0xb0 ==  crc8_dvb_s2          (0x00, "123456", 6), "crc8_dvb_s2"           );
    crc_assert(0x8e ==  crc8_ebu             (0xFF, "123456", 6), "crc8_ebu"              );
    crc_assert(0x5b ==  crc8_icode           (0xFD, "123456", 6), "crc8_icode"            );
    crc_assert(0xa8 ==  crc8_itu             (0x00, "123456", 6), "crc8_itu"              );
    crc_assert(0xec ==  crc8_maxim           (0x00, "123456", 6), "crc8_maxim"            );
    crc_assert(0x57 ==  crc8_rohc            (0xFF, "123456", 6), "crc8_rohc"             );
    crc_assert(0xab ==  crc8_wcdma           (0x00, "123456", 6), "crc8_wcdma"            );


    crc_assert(0x20e4 ==  crc16_ccit_zero   (0x0000, "123456", 6), "crc16_ccit_zero"    );
    crc_assert(0x29e4 ==  crc16_arc         (0x0000, "123456", 6), "crc16_arc"          );
    crc_assert(0x11da ==  crc16_aug_ccitt   (0x1D0F, "123456", 6), "crc16_aug_ccitt"    );
    crc_assert(0xb16e ==  crc16_buypass     (0x0000, "123456", 6), "crc16_buypass"      );
    crc_assert(0x2ef4 ==  crc16_ccitt_false (0xFFFF, "123456", 6), "crc16_ccitt_false"  );
    crc_assert(0x5059 ==  crc16_cdma2000    (0xFFFF, "123456", 6), "crc16_cdma2000"     );
    crc_assert(0xb3be ==  crc16_dds_110     (0x800D, "123456", 6), "crc16_dds_110"      );
    crc_assert(0x8ffe ==  crc16_dect_r      (0x0000, "123456", 6), "crc16_dect_r"       );
    crc_assert(0x8fff ==  crc16_dect_x      (0x0000, "123456", 6), "crc16_dect_x"       );
    crc_assert(0x57de ==  crc16_dnp         (0x0000, "123456", 6), "crc16_dnp"          );
    crc_assert(0x062a ==  crc16_en_13757    (0x0000, "123456", 6), "crc16_en_13757"     );
    crc_assert(0xd10b ==  crc16_genibus     (0xFFFF, "123456", 6), "crc16_genibus"      );
    crc_assert(0xd61b ==  crc16_maxim       (0x0000, "123456", 6), "crc16_maxim"        );
    crc_assert(0x198d ==  crc16_mcrf4xx     (0xFFFF, "123456", 6), "crc16_mcrf4xx"      );
    crc_assert(0x31c0 ==  crc16_t10_dif     (0x0000, "123456", 6), "crc16_t10_dif"      );
    crc_assert(0x2cd1 ==  crc16_teledisk    (0x0000, "123456", 6), "crc16_teledisk"     );
    crc_assert(0xcd1b ==  crc16_usb         (0xFFFF, "123456", 6), "crc16_usb"          );
    crc_assert(0x11fd ==  crc16_kermit      (0x0000, "123456", 6), "crc16_kermit"       );
    crc_assert(0x32e4 ==  crc16_modbus      (0xFFFF, "123456", 6), "crc16_modbus"       );
    crc_assert(0xe672 ==  crc16_x_25        (0xFFFF, "123456", 6), "crc16_x_25"         );
    crc_assert(0x20e4 ==  crc16_xmodem      (0x0000, "123456", 6), "crc16_xmodem"       );


    crc_assert(0x0972d361 ==  crc32         (0xFFFFFFFF, "123456", 6), "crc32"          );
    crc_assert(0x270f9370 ==  crc32_bzip2   (0xFFFFFFFF, "123456", 6), "crc32_bzip2"    );
    crc_assert(0x41357186 ==  crc32_c       (0xFFFFFFFF, "123456", 6), "crc32_c"        );
    crc_assert(0x0c61f70a ==  crc32_d       (0xFFFFFFFF, "123456", 6), "crc32_d"        );
    crc_assert(0xd8f06c8f ==  crc32_mpeg2   (0xFFFFFFFF, "123456", 6), "crc32_mpeg2"    );
    crc_assert(0x1d752f02 ==  crc32_posix   (0x00000000, "123456", 6), "crc32_posix"    );
    crc_assert(0x7ccd1a36 ==  crc32_q       (0x00000000, "123456", 6), "crc32_q"        );
    crc_assert(0xf68d2c9e ==  crc32_jamcrc  (0xFFFFFFFF, "123456", 6), "crc32_jamcrc"   );
    crc_assert(0xf036f1c2 ==  crc32_xfer    (0x00000000, "123456", 6), "crc32_xfer"     );


    return 0;
}